home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 359_11 / patch5.000 / GO32_TABLES.ASM < prev    next >
Assembly Source File  |  1991-09-11  |  3KB  |  168 lines

  1. ; This is file TABLES.ASM
  2. ;
  3. ; Copyright (C) 1991 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  4. ;
  5. ; This file is distributed under the terms listed in the document
  6. ; "copying.dj", available from DJ Delorie at the address above.
  7. ; A copy of "copying.dj" should accompany this file; if not, a copy
  8. ; should be available from where this file was obtained.  This file
  9. ; may not be distributed without a verbatim copy of "copying.dj".
  10. ;
  11. ; This file is distributed WITHOUT ANY WARRANTY; without even the implied
  12. ; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. ;
  14.  
  15. ;    History:20,1
  16.     title    tables
  17.     .386p
  18.  
  19.     include    build.inc
  20.     include    segdefs.inc
  21.     include tss.inc
  22.     include gdt.inc
  23.     include idt.inc
  24.  
  25. ;------------------------------------------------------------------------
  26.  
  27.     start_data16
  28.  
  29.     extrn    _tss_ptr:word
  30.     extrn    _was_exception:word
  31.     extrn    _npx:byte
  32.  
  33.     public    _was_user_int
  34. _was_user_int    dw    0
  35.  
  36.     public    ivec_number
  37. ivec_number    db    ?
  38.  
  39. has_error    db    0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,0,0
  40.  
  41.     end_data16
  42.  
  43. ;------------------------------------------------------------------------
  44.  
  45.     .286c
  46.     start_bss
  47.  
  48.     public    _gdt
  49. _gdt    label    gdt_s
  50.     db    type gdt_s * g_num dup (?)
  51.  
  52.     public    _idt
  53. _idt    label    idt_s
  54.     db    type idt_s * 256 dup (?)
  55.  
  56.     public    _i_tss
  57. _i_tss    label    tss_s
  58.     db    type tss_s dup (?)
  59.  
  60.     end_bss
  61.     .386p
  62.  
  63. ;------------------------------------------------------------------------
  64.  
  65.     start_code16
  66.  
  67. sound    macro
  68.     local    wait_loop
  69.     local    wait_loop1
  70.     mov    al,033h
  71.     out    061h,al
  72.     mov    ecx,100000h
  73. wait_loop:
  74.     loopd    wait_loop
  75.     mov    al,032h
  76.     out    61h,al
  77.     mov    ecx,100000h
  78. wait_loop1:
  79.     loop    wait_loop1
  80.     endm
  81.  
  82. ivec    macro    n
  83.     push    ds
  84.     push    g_rdata
  85.     pop    ds
  86.     mov    ivec_number,n
  87.     pop    ds
  88.     db    0eah
  89.     dw    0, g_itss
  90.     endm
  91.  
  92.     public    _ivec0, _ivec1
  93. _ivec0:
  94.     ivec 0
  95. _ivec1:
  96.     x=1
  97.     rept 255
  98.      ivec x
  99.      x=x+1
  100.     endm
  101.  
  102.     public    _interrupt_common
  103. _interrupt_common:
  104.     cli
  105.     mov    bx,g_rdata
  106.     mov    ds,bx
  107.     mov    bx,_tss_ptr
  108.     mov    al,ivec_number
  109.     mov    [bx].tss_irqn,al
  110.     mov    esi,[bx].tss_esp
  111.     mov    fs,[bx].tss_ss        ; fs:esi -> stack
  112.     cmp    al,16
  113.     ja    has_no_error
  114.     mov    ah,0
  115.     mov    di,ax
  116.     cmp    has_error[di],0
  117.     je    has_no_error
  118.     mov    eax,fs:[esi]
  119.     mov    [bx].tss_error,eax
  120.     add    esi,4
  121. has_no_error:
  122.     mov    eax,fs:[esi]        ; eip
  123.     mov    [bx].tss_eip,eax
  124.     mov    eax,fs:[esi+4]
  125.     mov    [bx].tss_cs,ax
  126.     mov    eax,fs:[esi+8]
  127.     mov    [bx].tss_eflags,eax
  128.     add    esi,12
  129.     mov    [bx].tss_esp,esi    ; store corrected stack pointer
  130.     mov    _was_exception,1
  131.     jmpt    g_ctss            ; pass control back to real mode
  132.     cli
  133.     jmp    _interrupt_common    ; it's a task
  134.  
  135.     extrn    graphics_fault:near
  136.  
  137.     public    _page_fault
  138. _page_fault:
  139.     cli
  140.     mov    bx,g_rdata
  141.     mov    ds,bx
  142.     mov    es,bx
  143.     mov    eax,cr2
  144. if 1
  145.     cmp    eax,0e0000000h
  146.     jb    regular_pf
  147.     cmp    eax,0e0300000h
  148.     ja    regular_pf
  149.     jmp    graphics_fault
  150. regular_pf:
  151. endif
  152.     mov    bx,_tss_ptr
  153.     mov    [bx].tss_irqn,14    ; page fault
  154.     mov    [bx].tss_cr2,eax
  155.     pop    eax
  156.     mov    [bx].tss_error,eax
  157.     mov    eax,0
  158.     mov    cr2,eax            ; so we can tell INT 0D from page fault
  159.     mov    _was_exception,1
  160.     jmpt    g_ctss
  161.     jmp    _page_fault
  162.  
  163.     end_code16
  164.  
  165. ;------------------------------------------------------------------------
  166.  
  167.     end
  168.